<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Many to One - Foreign Key</title>
</head>
<body>
  <pre class="brush: java">
//Package declaration and imports omitted for brevity
//Employee.java source
@Entity(name = "MtoUniEmployee")
@Table(name = "mto_uni_employee")
public class Employee implements Serializable {
	
	private int id;
	private String name;
	private Project project;
	
	public Employee() {}
	
	public Employee(String name) {
		super();
		this.name = name;
	}
	
	@Id
	@GeneratedValue
	public int getId() {
		return id;
	}

	private void setId(int id) {
		this.id = id;
	}

	@Column(nullable = false, length = 30)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@ManyToOne
	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}
}

/////////////////////////////////////////////////

//Project.java source
@Entity(name = "MtoUniProject")
@Table(name = "mto_uni_project")
public class Project implements Serializable {

	private int id;
	private String name;
	
	public Project() {}
	
	public Project(String name) {
		this.name = name;
	}

	@Id
	@GeneratedValue
	public int getId() {
		return id;
	}

	private void setId(int id) {
		this.id = id;
	}

	@Column(nullable = false, length = 30)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}	
}
  </pre>
</body>
</html>
